<?php

class Cat_Assert
{
	public static function assertType( $val, $type, $name = null )
	{
		if ( !is_array( $type ) )
		{
			$type = array( $type );
		}
		
		foreach( $type as $typ )
		{		
			switch( trim($typ) )
			{
				case 'string': 	if ( is_string($val) ) 		return true; break;
				case 'numeric':	if ( is_numeric($val) ) 	return true; break;
				case 'array':	if ( is_array($val) ) 		return true; break;
				case 'object':	if ( is_object($val) ) 		return true; break;
				case 'bool':	if ( is_bool($val) ) 		return true; break;
				default:		if ( is_a($val, $type) )	return true;
			}
		}
		
		if ( $name == null )
		{
			$name = $val;
		}
		
		throw new Cat_AssertException( $name, implode(',', $type) );
	}
}